package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.Role;

@Repository
public interface RoleDao extends JpaRepository<Role, Integer>, JpaSpecificationExecutor<Role> {

	@Query("from Role where name = ?1")
	List<Role> find(String name);

	@Query("from Role where name like ?1")
	List<Role> findLike(String name);

	@Query(value = "select * from Role limit ?, ?", nativeQuery = true)
	List<Role> findPage(Integer offset, Integer size);

	@Query(value = "select * from Role where name = ? limit ?, ?", nativeQuery = true)
	List<Role> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from Role where name like ? limit ?, ?", nativeQuery = true)
	List<Role> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from Role where name = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from Role where name like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from Role order by id asc")
	List<Role> findAllAsc();

	@Query("select id from Role where code in ?1")
	List<Integer> findByCodeIn(List<String> code);
}

